#!/usr/bin/env Node

const inquirer = require('inquirer')
const path = require('path')
const fs = require('fs');
const ejs = require('ejs')
inquirer.prompt([{
		type: 'input',
		name: 'name',
		message: 'what is your project name？'
	}])
	.then((data) => {
		//模板路径
		const templatesPath = path.join(__dirname, 'templates');
		//目标路径
		const destPath = process.cwd();
		//获取模板文件输出到目标位置
		fs.readdir(templatesPath, (err, content) => {
			if (err) {
				return err
			}
			content.forEach(filename => {
				ejs.renderFile(path.join(templatesPath, filename), data, (err2, content2) => {
					if (err2) {
						throwError(err2)
					}
					fs.writeFileSync(path.join(destPath, filename), content2)
				})
			})
		})
	})
